package com.calclab.hablar.chatmedia.client.preferences;

import java.util.HashMap;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class AddMediaWidget extends Composite implements AddMediaDisplay{
    
    private static AddMediaWidgetUiBinder uiBinder = GWT.create(AddMediaWidgetUiBinder.class);

    interface AddMediaWidgetUiBinder extends UiBinder<Widget, AddMediaWidget> {
    }

    @UiField
    Button addButton;
    
    @UiField
    Button closeButton; 
    
    @UiField
    TextBox typeBox;
    
    
    @UiField
    TextBox accountBox;
    
    protected final HashMap<Field, TextBox> fields = new HashMap<Field, TextBox>();
    
    public AddMediaWidget() {
	initWidget(uiBinder.createAndBindUi(this));
	addButton.setText("Add");
	closeButton.setText("Close");
	init("Hablar-AddMedia");
    }
    
    
    @Override
    public HasClickHandlers getAdd() {
	return addButton;
    }
    
    @Override
    public HasClickHandlers getClose() {
	return closeButton;
    }
    
    @Override
    public Widget asWidget() {
	return this;
    }
    
    @Override
    public HasText getField(Field field) {
	// TODO Auto-generated method stub
	return fields.get(field);
    }
    
    protected void init(String idPrefix) {
	fields.put(Field.type, typeBox);
	fields.put(Field.account, accountBox);
	
	for (final Field field : fields.keySet()) {
	    fields.get(field).ensureDebugId(idPrefix + "-" + field.toString());
	}

    }

//    @UiHandler("addButton")
//    void onClick(ClickEvent e) {
//	String type = typeBox.getText();
//	String account = accountBox.getText();
//	//send to server.
//    }
//    
//    @UiHandler("closeButton")
//    void onSignOutClicked(ClickEvent event) {
//	this.setVisible(false);
//    }
}
